package com.xiaoyang.forum.common.util;

import org.springframework.util.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author: XiaoYang
 * @CreateTime: 2025-08-21
 * @Description:
 */
public class RegexUtil {

    private static final String emailRegex = "^[a-z0-9]+([._\\\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$";

    private static final String PHONE_REGEX = "^1[3-9]\\d{9}$";


    /**
     * 验证邮箱
     * 邮箱：xxx@xx.xxx(形如：abc@qq.com)
     * @param content
     * @return
     */
    public static boolean checkMail(String content) {
        if (!StringUtils.hasText(content)) {
            return false;
        }
        return Pattern.matches(emailRegex, content);
    }

    /**
     * 验证手机号
     * @param phoneNumber
     * @return
     */
    public static boolean isValidPhoneNumber(String phoneNumber) {
        Pattern pattern = Pattern.compile(PHONE_REGEX);
        Matcher matcher = pattern.matcher(phoneNumber);
        return matcher.matches();
    }
}
